package com.example.adminui.controller;

import com.example.adminui.entity.SalesPerformance;
import com.example.adminui.service.SalesPerformanceService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sales-performances")
public class SalesPerformanceController {
    private final SalesPerformanceService salesPerformanceService;

    public SalesPerformanceController(SalesPerformanceService salesPerformanceService) {
        this.salesPerformanceService = salesPerformanceService;
    }

    @PostMapping
    public void create(@RequestBody SalesPerformance salesPerformance) {
        salesPerformanceService.save(salesPerformance);
    }

    @PutMapping("/{id}")
    public void update(@PathVariable Long id, @RequestBody SalesPerformance salesPerformance) {
        salesPerformance.setId(id);
        salesPerformanceService.updateById(salesPerformance);
    }

    @DeleteMapping("/{id}")
    public void delete(@PathVariable Long id) {
        salesPerformanceService.removeById(id);
    }

    @GetMapping("/{id}")
    public SalesPerformance get(@PathVariable Long id) {
        return salesPerformanceService.getById(id);
    }
}